package com.xz.group12306.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import com.xz.group12306.business.service.TicketService;
import com.xz.group12306.business.service.Impl.TicketServiceImpl;
import com.xz.group12306.domain.Ticket;

/**
 * Servlet implementation class TicketServlet
 */
@WebServlet("/TicketServlet")
public class TicketServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TicketServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	    this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		int pageSize=Integer.parseInt(request.getParameter("pageSize"));
		int start=Integer.parseInt(request.getParameter("start"));

		
		String depature=request.getParameter("depature");
		String destinction=request.getParameter("destinction");
		//String starttime=request.getParameter("starttime");
		//System.out.println(starttime);
		Ticket ticket=new Ticket();
		ticket.setDepature(depature);
		ticket.setDestinction(destinction);
			
		
		TicketService ticketService=new TicketServiceImpl();
		List<Ticket> tickets=ticketService.findTicketList(ticket, start, pageSize);
		HttpSession session=request.getSession();
		
		//	List<User> users=manageService.getUserList(pageSize, start, user);
			session.setAttribute("tickets", tickets);
			response.sendRedirect("user/showTicket.jsp");
	}

}
